/**
 * 
 */
package edu.umd.clip.lm.playground;

import java.io.File;

import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.EnvironmentLockedException;

import edu.berkeley.nlp.util.*;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class RenameDb {
	public static class Options {
        @Option(name = "-db", required = true, usage = "Berkeley DB environment")
		public String db;
        @Option(name = "-from", required = true, usage = "Old db name")
		public String from;
        @Option(name = "-to", required = true, usage = "New db name")
        public String to;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
        OptionParser optParser = new OptionParser(Options.class);
        final Options opts = (Options) optParser.parse(args, true);

		EnvironmentConfig envConf = new EnvironmentConfig();
		envConf.setAllowCreate(false);
		//envConf.setSharedCache(true);
		envConf.setTransactional(false);

		try {
			Environment env = new Environment(new File(opts.db), envConf);
			env.renameDatabase(null, opts.from, opts.to);
			env.close();
		} catch (EnvironmentLockedException e) {
			e.printStackTrace();
		} catch (DatabaseException e) {
			e.printStackTrace();
		}

	}

}
